#include "stdio.h"
#include "string.h"
#include "stdlib.h"

#define SIZE 5 

/*
unsigned char c ; //0-255
char c //0 -127
 */

 /*
int sckClit_sen(void *hanle, unsigned char *buf, int buflen)
//文件在磁盘上的存放有两种方式 asc方式可以的 、非asc（bin方式）
*/

typedef struct Student_
{    
	char name[10];
	int num;
	int age;
	char addr[15];
}Student;

/*
#include <stdio.h>

size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);

size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);

The function fread() reads nitems objects, each size bytes long, from the stream pointed to by stream, storing them at the location given by ptr.

The function fwrite() writes nitems objects, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr.

RETURN VALUE
       On  success,  fread()  and  fwrite() return the number of items read or
       written.  This number equals the number of bytes transferred only  when
       size  is 1.  If an error occurs, or the end of the file is reached, the
       return value is a short item count (or zero).

       fread() does not distinguish between end-of-file and error, and callers
       must use feof(3) and ferror(3) to determine which occurred.
	   
*/


int main()
{  
	int  i;
	FILE *fp = NULL;

	Student student[5];

	if((fp=fopen("./student1.data","wb"))==NULL)
	{    
		printf("func fopen() error\n");
		return -1;
	}

	for (i=0; i<5; i++)
	{
		memset(&student[i], 0, sizeof(Student));
		sprintf(student[i].name, "name%d", i+1);

		//把第二个参数组合的字符串，打印到第一个参数buf中。
		//sprintf(student[i].name,"name%d", i+1);
		//fprintf(fp,"name%d", i+1);
	}

	for(i=0;i<5;i++)
	{
		if(fwrite(&student[i],sizeof(Student),1,fp)!=1)
			printf("file write error\n");
	}

	if(fp != NULL)
	{
		fclose(fp);
		fp = NULL;
	}
	
	return 0;
}

